from django.db import models
# 用户表
class User(models.Model):
    name=models.CharField(max_length=10,verbose_name='用户名')
    mobile=models.CharField(max_length=11,verbose_name="手机号")
    pwd=models.CharField(max_length=200,verbose_name="密码")
    property=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="资产金额")
    no_property=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="资产锁定金额")
    role_id=models.IntegerField(verbose_name="所属角色")
    class Meta:
        db_table='user'
    def __str__(self):
        return self.name

# 三方登录表
class Sf_login(models.Model):
    sf_type=models.CharField(max_length=20,verbose_name='三方类型')
    sf_token=models.CharField(max_length=100,verbose_name='三方token')
    uid=models.CharField(max_length=100,verbose_name='三方id')
    userid=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="用户id")
    class Meta:
        db_table='sf_login'
    def __str__(self):
        return self.sf_type

# 角色表
class Role(models.Model):
    name=models.CharField(max_length=10,verbose_name='角色姓名')
    class Meta:
        db_table='role'
    def __str__(self):
        return self.name

# 资源表
class Resource(models.Model):
    name=models.CharField(max_length=10,verbose_name='角色姓名')
    url = models.CharField(max_length=10,verbose_name="url地址")
    uid=models.IntegerField(verbose_name="自关联id")
    class Meta:
        db_table='Resource'
    def __str__(self):
        return self.name

# 角色权限表
class Role_resource(models.Model):
    role_id=models.ForeignKey("Role",on_delete=models.CASCADE,verbose_name="角色id")
    resource_id=models.ForeignKey("Resource",on_delete=models.CASCADE,verbose_name="资源id")
    class Meta:
        db_table='role_resource'
    def __str__(self):
        return self.role_id

# 类型表
class It_type(models.Model):
    type_name=models.CharField(max_length=10,verbose_name="类型名称")
    pid = models.IntegerField(verbose_name="自关联id")
    class Meta:
        db_table='it_type'
    def __str__(self):
        return self.type_name

# 外包表（请求表）
class Demand(models.Model):
    code=models.CharField(max_length=40,verbose_name="雪花算法id")
    project_name=models.CharField(max_length=50,verbose_name="项目名称")
    typelei=models.CharField(max_length=10,verbose_name="（个人，企业）类型")
    describe=models.TextField(verbose_name="描述")
    img=models.CharField(max_length=200,verbose_name="项目封面")
    price=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="项目金额")
    userid=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="发布项目的用户id")
    type_id=models.ForeignKey("It_type",on_delete=models.CASCADE,verbose_name="类型id")
    charge_mode=models.CharField(max_length=10,verbose_name="计费方式")
    mobile=models.CharField(max_length=11,verbose_name="手机号")
    ask_fro=models.TextField(verbose_name="项目要求(内容)")
    state=models.IntegerField(verbose_name="状态（1为未审核，2为审核通过，3为不通过）")
    ttm=models.DateTimeField(verbose_name='时间')
    class Meta:
        db_table='demand'
    def __str__(self):
        return self.project_name

# 外包表1（请求表）
class Demand1(models.Model):
    code = models.CharField(max_length=40, verbose_name="雪花算法id")
    project_name = models.CharField(max_length=50, verbose_name="项目名称")
    typelei = models.CharField(max_length=10, verbose_name="（个人，企业）类型")
    describe = models.TextField(verbose_name="描述")
    img = models.CharField(max_length=200, verbose_name="项目封面")
    price = models.DecimalField(max_digits=10, decimal_places=2, default=0, verbose_name="项目金额")
    userid = models.ForeignKey("User", on_delete=models.CASCADE, verbose_name="发布项目的用户id")
    type_id = models.ForeignKey("It_type", on_delete=models.CASCADE, verbose_name="类型id")
    charge_mode = models.CharField(max_length=10, verbose_name="计费方式")
    mobile = models.CharField(max_length=11, verbose_name="手机号")
    ask_fro = models.TextField(verbose_name="项目要求(内容)")
    state = models.IntegerField(verbose_name="状态（1为未审核，2为审核通过，3为不通过）")
    ttm=models.DateTimeField(verbose_name='时间')
    class Meta:
        db_table='demand1'
    def __str__(self):
        return self.project_name

# 外包表2（请求表）
class Demand2(models.Model):
    code = models.CharField(max_length=40, verbose_name="雪花算法id")
    project_name = models.CharField(max_length=50, verbose_name="项目名称")
    typelei = models.CharField(max_length=10, verbose_name="（个人，企业）类型")
    describe = models.TextField(verbose_name="描述")
    img = models.CharField(max_length=200, verbose_name="项目封面")
    price = models.DecimalField(max_digits=10, decimal_places=2, default=0, verbose_name="项目金额")
    userid = models.ForeignKey("User", on_delete=models.CASCADE, verbose_name="发布项目的用户id")
    type_id = models.ForeignKey("It_type", on_delete=models.CASCADE, verbose_name="类型id")
    charge_mode = models.CharField(max_length=10, verbose_name="计费方式")
    mobile = models.CharField(max_length=11, verbose_name="手机号")
    ask_fro = models.TextField(verbose_name="项目要求(内容)")
    state = models.IntegerField(verbose_name="状态（1为未审核，2为审核通过，3为不通过）")
    ttm=models.DateTimeField(verbose_name='时间')

    class Meta:
        db_table='demand2'
    def __str__(self):
        return self.project_name

# 接单记录表
class Receipt_record(models.Model):
    code = models.CharField(max_length=40, verbose_name="雪花算法id")
    join_time=models.DateTimeField(verbose_name="接单时间")
    user_id = models.ForeignKey("User", on_delete=models.CASCADE, verbose_name="接受项目的用户id")
    state=models.IntegerField(verbose_name="状态（（1未完成），（2已完成））")
    class Meta:
        db_table='receipt_record'
    def __str__(self):
        return self.code

# 银行表
class Bank(models.Model):
    sf_yh=models.CharField(max_length=20,verbose_name="银行卡类型")
    bank_card=models.CharField(max_length=20,verbose_name="银行卡号")
    money=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="银行卡金额")
    userid=models.ForeignKey("User", on_delete=models.CASCADE, verbose_name="用户id")
    class Meta:
        db_table="bank"
    def __str__(self):
        return self.sf_yh

# 订单表
class Order(models.Model):
    userid=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="角色id")
    order_code=models.CharField(max_length=50,verbose_name="订单号")
    code_id = models.CharField(max_length=30,verbose_name="雪花算法id")
    a_time=models.DateTimeField(verbose_name="开始时间")
    b_time=models.DateTimeField(verbose_name="结束时间")
    status=models.IntegerField(verbose_name="状态（1.发布中），（2.交易中），（3.已完成）")

# 订单详情表
class order2(models.Model):
    userid = models.ForeignKey("User", on_delete=models.CASCADE, verbose_name="角色id")
    epiboly_id=models.CharField(max_length=30,verbose_name="雪花算法唯一id")
    price=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="交易金额")
    dd_id=models.ForeignKey('Order',on_delete=models.CASCADE,verbose_name="订单id")
    class Meta:
        db_table='order2'
    def __str__(self):
        return self.epiboly_id

# 充值记录表
class recharge_record(models.Model):
    dd_code=models.CharField(max_length=20,verbose_name="订单编号")
    yhk_code=models.CharField(max_length=20,verbose_name="银行卡号")
    money=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="交易金额")
    mtime=models.DateTimeField(verbose_name="充值订单生成时间")
    state=models.CharField(max_length=3,verbose_name="订单状态",default="未完成")
    userid =models.IntegerField(verbose_name="用户id")
    trade_no=models.CharField(max_length=200,verbose_name="流水号")
    class Meta:
        db_table='recharge_record'
    def __str__(self):
        return self.yhk_code


#  金额记录表
class Amount_record(models.Model):
    price=models.DecimalField(max_digits=10,decimal_places=2,default=0,verbose_name="金额")
    ptime=models.DateTimeField(verbose_name="时间")
    user_id=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="用户id")
    describe=models.TextField(verbose_name="金额流向描述")
    class Meta:
        db_table='Amount_record'
    def __str__(self):
        return self.price

# 人才表
class Talents(models.Model):
    userid=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="用户id")
    it_id=models.ForeignKey("It_type",on_delete=models.CASCADE,verbose_name="类型id")
    class Meta:
        db_table='talents'
    def __str__(self):
        return self.userid

# 店铺表
class Store(models.Model):
    name=models.CharField(max_length=50,verbose_name="名称")
    boss_id =models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="用户id")
    type = models.ForeignKey("It_type", on_delete=models.CASCADE, verbose_name="类型id")
    describe=models.TextField(verbose_name="店铺描述")
    ces_img=models.CharField(max_length=50,verbose_name="店铺图片")
    class Meta:
        db_table='store'
    def __str__(self):
        return self.name

#店铺员工表
class Store_user(models.Model):
    dp_id=models.ForeignKey("Store",on_delete=models.CASCADE,verbose_name="店铺id")
    us_id=models.ForeignKey("User",on_delete=models.CASCADE,verbose_name="用户id")
    class Meta:
        db_table='Store_user'
    def __str__(self):
        return self.dp_id

# 后台登录
class I_Login(models.Model):
    name=models.CharField(max_length=11,verbose_name="名称")
    mobile=models.CharField(max_length=11,verbose_name="手机号")
    class Meta:
        db_table='i_login'
    def __str__(self):
        return self.name

# 角色
class I_role(models.Model):
    name=models.CharField(max_length=10,verbose_name="角色名称")
    class Meta:
        db_table='i_role'
    def __str__(self):
        return self.name

# 资源表
class I_resource(models.Model):
    name=models.CharField(max_length=20,verbose_name="姓名")
    uid=models.IntegerField(verbose_name="自关联id")
    class Meta:
        db_table='l_resource'
    def __str__(self):
        return self.name

# 角色资源表
class  Irole_resource(models.Model):
    irole_id=models.ForeignKey("I_role",on_delete=models.CASCADE,verbose_name="角色id")
    iresource_id=models.ForeignKey("I_resource",on_delete=models.CASCADE,verbose_name="资源id")
    class Meta:
        db_table='Irole_resource'
    def __str__(self):
        return self.irole_id

# 身份认证
class identity(models.Model):
    code=models.CharField(max_length=18,verbose_name="身份证号")
    name=models.CharField(max_length=5,verbose_name="用户姓名")
    itype=models.CharField(max_length=2,verbose_name="认证类型")
    userid=models.ForeignKey('User',on_delete=models.CASCADE,verbose_name="用户id")
    class Meta:
        db_table='identity'
    def __str__(self):
        return self.code










